﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TTEngine.Impl.Desktop;

namespace voidbox.Code
{
    internal static class StartConfig
    {
   
        public static string StartApp
        {
            get;
            private set;
        }
      
        public static void Init()
        {
            var lines = System.IO.File.ReadAllLines("start.ini");
            string curGroup = "";
            foreach (var line in lines)
            {
                if (line.Length == 0)
                    continue;
                if (line[0] == '#')
                    continue;
                if (line[0] == '[')
                    curGroup = line.Substring(1, line.IndexOf(']') - 1);
                else
                    ParseLine(curGroup, line);

            }
        }
        static void ParseLine(string curGroup, string line)
        {
            var infos = line.Split(new char[] { ' ', '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (infos.Length > 1)
            {
                var key = infos[0];
                if (curGroup == "StartOption")
                {
                   
                    if (key == "StartApp")
                    {
                        StartApp = (infos[1]);
                    }
                  
                }

            }
            if(StartApp==null)
            {
                throw new Exception("start.ini not config StartApp");
            }
        }
    }
}
